const debug = require('debug')('rlcas:kafka')
const kafka = require('kafka-node');
const HighLevelProducer = kafka.HighLevelProducer;
const client = new kafka.KafkaClient({ kafkaHost: '172.16.3.62:9092,172.16.3.65:9092,172.16.3.70:9092' });
const producer = new HighLevelProducer(client);
const topic = process.env.NODE_ENV === 'production' ? 'buried_point' : 'log_test'
const logdebug = 'log_debug';
/**
 * 
 * @param {array} data 
 */
module.exports = {
  log: function (data) {
    if (data.length == 0) return;
    producer.send([{ topic: topic, messages: data, attributes: 0 }], function (err, data) {
      if (err) return debug(topic + '.error', err)
      debug('topic:', data)
    })
  },
  debug: function (data) {
    if (data.length == 0) return;
    producer.send([{ topic: topic, messages: data, attributes: 0 }], function (err, data) {
      if (err) return debug('logdebug.error', err)
      debug('logdebug:', data)
    })
  },
}